package com.cskaoyan.service;

import com.cskaoyan.bean.MarketAddress;
import com.cskaoyan.bean.MarketAddressExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketAddressMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月27日 23:51
 */
public class UserAdressServiceimpl implements UserAdressService {

    @Override
    public CommonData query(Integer page, Integer limit, String sort, String order) {
        MarketAddressMapper mapper = MyBatisUtil.getMapper(MarketAddressMapper.class);
        PageHelper.startPage(page, limit);
        MarketAddressExample marketAddressExample = new MarketAddressExample();
        marketAddressExample.setOrderByClause(sort + " " + order);
        List<MarketAddress> marketAddresses = mapper.selectByExample(marketAddressExample);
        PageInfo<MarketAddress> marketAddressesPageInfo = new PageInfo<>(marketAddresses);
        return CommonData.data(marketAddressesPageInfo);
    }

    @Override
    public List<MarketAddress> selectByuserId(Integer userId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketAddressMapper mapper = sqlSession.getMapper(MarketAddressMapper.class);
        List<MarketAddress> marketAddresses = mapper.selectByuserId(userId);
        for (MarketAddress marketAddress : marketAddresses) {
            System.out.println(marketAddress);
        }
        return marketAddresses;
    }

    @Override
    public List<MarketAddress> selectByFuzzyName(String mohu) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketAddressMapper mapper = sqlSession.getMapper(MarketAddressMapper.class);
        List<MarketAddress> list = mapper.selectByFuzzyName(mohu);
        for (MarketAddress marketAddress : list) {
            System.out.println(marketAddress);
        }
        return list;
    }
}
